package com.jl.commons.utils;

import com.jl.commons.constant.ErrorCode;
import com.jl.commons.constant.ErrorMessage;
import sun.misc.BASE64Decoder;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 封装sun.misc.BASE64Decoder中对base64的各类方法
 */
public class BASE64 {

    public static String decode(String code){
        // BASE64解密
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] decoding;
        String value=null;
        try{
            decoding = decoder.decodeBuffer(code);
            value =  new String(decoding, StandardCharsets.UTF_8);
        } catch(IllegalArgumentException e1){
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return value;
    }

}
